﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;


namespace QuanLyThuNgan
{
    public partial class Frm_DanhSachNopTien : DevExpress.XtraEditors.XtraForm
    {
        public Frm_DanhSachNopTien()
        {
            InitializeComponent();
        }

        CaThuNganCTL caThuNganCtl = new CaThuNganCTL();
        CaThuNganDTO caThuNganDto = new CaThuNganDTO();
        public int iRowIndex;
        private void Frm_DanhSachNopTien_Load(object sender, EventArgs e)
        {
            dateTuNgay.DateTime = Uit.it_Date.CurrentDate2();
            dateDenNgay.DateTime = Uit.it_Date.CurrentDate2();
            gdcDSNopTien.DataSource = caThuNganCtl.m_SelectDanhSachNopTien(Uit.it_Parse.ToDateTime(dateTuNgay.EditValue).ToString("yyyy-MM-dd"), Uit.it_Parse.ToDateTime(dateDenNgay.EditValue).ToString("yyyy-MM-dd"));

        }

        //set STT danh sach ----------------------------------------------------------
        private void gvDSNopTien_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator)
            {
                if (e.RowHandle < 0)
                    e.Info.DisplayText = "";
                else
                    e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
            else
                e.Info.DisplayText = "STT";
            e.Info.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            gdcDSNopTien.DataSource = caThuNganCtl.m_SelectDanhSachNopTien(Uit.it_Parse.ToDateTime(dateTuNgay.EditValue).ToString("yyyy-MM-dd"), Uit.it_Parse.ToDateTime(dateDenNgay.EditValue).ToString("yyyy-MM-dd"));
        }

        private void gvDSNopTien_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {

            iRowIndex = e.FocusedRowHandle;

            Form f = FormHelpers.CheckChildFormShow("Frm_ChiTietXacNhanNopTien", this);
            if (f == null)
            {
                Frm_ChiTietXacNhanNopTien xnnt = new Frm_ChiTietXacNhanNopTien();
                xnnt.iIDCaThuNgan = Uit.it_Parse.ToInteger((sender as GridView).GetFocusedRowCellValue("IDCaThuNgan"));
                xnnt.sNguoiThuTien = Uit.it_Parse.ToString((sender as GridView).GetFocusedRowCellValue("NguoiThu"));
                xnnt.sNgayThu = Uit.it_Parse.ToString((sender as GridView).GetFocusedRowCellValue("NgayDangKy"));
                xnnt.sCaThu = Uit.it_Parse.ToString((sender as GridView).GetFocusedRowCellValue("TenCaLamViec"));
                xnnt.sNoiThu = Uit.it_Parse.ToString((sender as GridView).GetFocusedRowCellValue("TenDonVi"));
                xnnt.sNguoiNhan = Uit.it_Parse.ToString((sender as GridView).GetFocusedRowCellValue("NguoiXacNhan"));
                xnnt.sNgayNop = Uit.it_Parse.ToString((sender as GridView).GetFocusedRowCellValue("NgayXacNhan"));
                xnnt.MdiParent = this.ParentForm;
                xnnt.WindowState = FormWindowState.Maximized;
                xnnt.Show();
            }
            else
            {
                f.Activate();
                f.Focus();
            }
        }
    }
}